home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
abbrev4
/
ablookup.cb
< prev
next >
Wrap
Text File
|
1989-11-03
|
5KB
|
135 lines
#define TRUE 1
/*************************************************************************
* *
* ABLOOKUP.CB *
* *
* This contains the utility files used both by "abbrev" and *
* "suffix". Either package may be used alone in conjunction *
* with this file, and suffix no longer requires the full *
* abbrev to be used. *
* *
* Larry DeMar 10-19-89. *
* *
**************************************************************************
* *
* AB_LOOKUP *
* *
* This is called to look up a string in an abbreviation file. *
* *
* Parameter 0 = file part of file name to look in *
* Parameter 1 = string to lookup *
* Parameter 2 = global buffer id of system buffer we're using *
* Parameter 3 = filename for system buffer *
* *
* If parameter 2 is non-zero, then it is the id of a *
* system buffer containing the lookup file. Else, we *
* create the system buffer. Read the lookup file in, *
* and put the new buffer id to parameter 2. *
* *
* If the string is found to start in column 1 of the *
* lookup file, then the "return string" is on the *
* rest of the line in the file. The return string *
* is put back to parameter 1. *
* *
* This returns TRUE of FALSE based on whether the lookup *
* succeeded. *
* *
*************************************************************************/
ab_lookup (...)
{
string file_part,
abbreviation,
my_search_string,
sys_file_name;
int orig_buffer,
system_id,
return_code;
get_parm (0, file_part);
get_parm (1, abbreviation);
get_parm (2, system_id);
get_parm (3, sys_file_name);
orig_buffer = inq_buffer ();
if ( // abbrev file in buffer?
system_id)
set_buffer (system_id); // yep...go there
else
{
system_id = create_sys_buf (file_part, sys_file_name); // no...create it.
put_parm (2, system_id); // and pass it back.
}
top_of_buffer ();
sprintf (my_search_string, "<%s[ \t]\\c", abbreviation);
if (return_code = search_fwd (my_search_string, 1, 0))
put_parm (1, trim (ltrim (read ())));
set_buffer (orig_buffer);
return return_code;
}
/*************************************************************************
* *
* CREATE_SYS_BUF *
* *
* This is called to create the system buffer and read in *
* the abbreviation file. *
* *
* It returns the id of the buffer it creates. *
* *
*************************************************************************/
create_sys_buf (...)
{
int buf_id;
string file_part,
buffer_name;
get_parm (0, file_part);
get_parm (1, buffer_name);
buf_id = create_buffer ("abbrev_buf", buffer_name, TRUE);
set_buffer (buf_id);
read_file (get_abbrev_file (file_part)); // read in the file
return buf_id;
}
/*************************************************************************
* *
* GET_ABBREV_FILE *
* *
* This is called to return the full path of the abbrev *
* directory file. *
* *
* 1) if BABBREV is in environment, then it is *
* used as the path. *
* *
* 2) if BPATH is in environment, then it is *
* used as the path. *
* *
* 3) otherwise "C:\" is used as the path. *
* *
*************************************************************************/
#define ENV_1 "BABBREV"
#define ENV_2 "BPATH"
#define DEFAULT_PATH "c:"
get_abbrev_file (...)
{
string abbrev_path,
file_part;
int semi_spot;
get_parm (0, file_part);
if ((abbrev_path = inq_environment (ENV_1)) == "")
if ((abbrev_path = inq_environment (ENV_2)) == "")
abbrev_path = DEFAULT_PATH;
else
if (semi_spot = rindex (abbrev_path, ";"))
abbrev_path = substr (abbrev_path, semi_spot + 1);
return trim (ltrim (abbrev_path)) + ("\\" + file_part);
}